package com.example.administrator.pomelostreet.asynctask;

import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;

import com.example.administrator.pomelostreet.HttpUtils.HttpUtil;
import com.example.administrator.pomelostreet.HttpUtils.Item_list;
import com.example.administrator.pomelostreet.HttpUtils.NewClothFragmentJson2;

import java.util.List;

/**
 * Created by Administrator on 2017/2/12.
 */

public class Myasynctaski extends AsyncTask<String, Void, List<Item_list>> {
    private Context context;
    private youziCallBack callBack;
    private List<Item_list> item_lists;

    public Myasynctaski(Context context, youziCallBack callBack) {
        this.context = context;
        this.callBack = callBack;
    }


    @Override
    protected List<Item_list> doInBackground(String... params) {
        byte[] dataUseOkHttp = HttpUtil.getDataUseOkHttp(params[0]);
        String json = new String(dataUseOkHttp);
        if (json != null && json.length() > 0) {
            item_lists = NewClothFragmentJson2.parseJsonToList(json);
            Log.i("aaa","==="+item_lists.size()+"------------"+json);
        }

        return item_lists;

    }

    @Override
    protected void onPostExecute(List<Item_list> item_lists) {
        if (item_lists != null && item_lists.size() > 0) {
            callBack.send(item_lists);
        }

    }

    public interface youziCallBack {
        public void send(List<Item_list> list);
    }

}
